from settings import CONSUL_HOST, WEBHOOK
import requests
import json


def SendMessage(info):
    message = {
        "msgtype": "markdown",
        "markdown": {
            "title": "consul-watch告警",
            "text": f"#### {info['Type']} \n> "
                    f"- 变更主体：{info['Name']}\n>"
                    f"- 变更输出：{info['Output']} \n>"
                    f"- 变更地址：{CONSUL_HOST}"
        },
        "at": {
            "atMobiles": [
                ""
            ],
            "isAtAll": False
        }
    }
    headers = {'Content-Type': 'application/json'}
    try:
        requests.post(url=WEBHOOK, data=json.dumps(message), headers=headers)
    except Exception as e:
        print(e)
